﻿using Common;
using Configuration;
//using SuperSocket.SocketBase;
//using SuperSocket.SocketBase.Config;
//using SuperSocket.WebSocket;
//using SuperSocket.WebSocket.Protocol;
//using SuperWebSocket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WebSocket.Core
{
    /*
    internal class AppWebSocketServer : WebSocketServer
    {
        protected override bool Setup(IRootConfig rootConfig, IServerConfig config)
        {
            return base.Setup(rootConfig, config);
        }
        protected override bool RegisterSession(string sessionID, WebSocketSession appSession)
        {
            return base.RegisterSession(sessionID, appSession);
        }

        protected override void OnNewSessionConnected(WebSocketSession session)
        {
            /*
            string token = (session.Host + session.Path).QueryString(Constants.TokenName);
            if (string.IsNullOrEmpty(token))
            {
                session.Close(CloseReason.Unknown);
                Logger.Error("连接请求缺少Token信息！");
                return;
            }

            Logger.Info($"新的客户端:{session.SessionID}准备连接,token为:{token}");

            //解析token
            var dictPayload = JwtTokenHelper.Decode(token);
            if (dictPayload == null)
            {
                session.Close(CloseReason.Unknown);
                Logger.Error("Token错误！");
                return;
            }
            DateTime creatTime = dictPayload[Constants.ValidateFrom];
            DateTime expTime = dictPayload[Constants.ValidateTo];

            //检查令牌的有效期
            var utcNowTime = DateTime.UtcNow;

            //检查令牌的有效期
            if (creatTime > utcNowTime || utcNowTime > expTime)
            {
                session.Close(CloseReason.ApplicationError);
                Logger.Error("Token已过期！");
                return;
            }

            */

            //WebSocketDataManager.AddUser(token, session);

    //        base.OnNewSessionConnected(session);
    //    }
        
    //    protected override void OnSessionClosed(WebSocketSession session, CloseReason reason)
    //    {
    //        //string token = (session.Host + session.Path).QueryString(Constants.TokenName);
    //        //if (string.IsNullOrEmpty(token))
    //        //{
    //        //    base.OnSessionClosed(session, reason);
    //        //    return;
    //        //}
    //        //WebSocketDataManager.RemoveUserSession(token);
    //        base.OnSessionClosed(session, reason);
    //    }
    //}
    //*/
}
